package com.hunanwenli.service.impl;

import com.hunanwenli.service.RedisService;
import com.hunanwenli.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author wanzhenyu
 * @date 2021/6/6 23:17
 */
@Service
public class TokenServiceImpl implements TokenService {
    @Autowired
    private RedisService redisService;
    @Override
    public void createListToken(Long redisKey, Long tokenQuantity,Long time) {
        List<String> listToken = getListToken(redisKey,tokenQuantity);
        redisService.setList("kill"+redisKey, listToken,time);
    }
    private List<String> getListToken(Long redisKey, Long tokenQuantity) {
        List<String> listToken = new ArrayList<>();
        for (int i = 0; i < tokenQuantity; i++) {
            String token = redisKey+ UUID.randomUUID().toString().replace("-", "");
            listToken.add(token);
        }
        return listToken;
    }
}
